package com.ibeeking.gmc.global.g.rest.controller.v1;

import com.ibeeking.gmc.global.g.rest.service.IDictValueService;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.gmc.global.service.common.param.DictValueParam;
import com.ibeeking.gmc.global.service.common.query.DictValuePageQuery;
import com.ibeeking.gmc.global.service.common.vo.DictSelectVO;
import com.ibeeking.gmc.global.service.common.vo.DictValuePageVO;
import com.ibeeking.gmc.global.service.common.vo.DictValueVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName DictValueController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-02 16:06
 **/
@RestController
@RequestMapping("/g/dictValue/v1")
public class DictValueController {

    @Resource
    private IDictValueService dictValueServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "下拉列表字典值查询")
    @GetMapping(value = "/queryListByType/{dictType}")
    public List<DictSelectVO> queryListByType(@PathVariable String dictType) {
        return dictValueServiceImpl.queryListByType(dictType);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分页查询字典值列表")
    @PostMapping(value = "/pageList")
    public Page<DictValuePageVO> pageList(@RequestBody @Validated DictValuePageQuery dictValuePageQuery) {
        return dictValueServiceImpl.pageList(dictValuePageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "新增字典值")
    @PostMapping(value = "/add")
    public Boolean add(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Insert.class) DictValueParam dictValueParam) {
        dictValueParam.setCreateBy(currentUser.getId());
        return dictValueServiceImpl.add(dictValueParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改字典值")
    @PostMapping(value = "/modify")
    public Boolean modify(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Update.class) DictValueParam dictValueParam) {
        dictValueParam.setModifyBy(currentUser.getId());
        return dictValueServiceImpl.modify(dictValueParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询字典值")
    @GetMapping(value = "/view/{id}")
    public DictValueVO view(@PathVariable("id") Long id) {
        return dictValueServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "启用/禁用字典")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@LoginUser CurrentUser currentUser, @PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return dictValueServiceImpl.changeStatus(id, status, currentUser.getId());
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除字典值")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return dictValueServiceImpl.del(id);
    }
}